<?php
require_once("../inc/connect.php");
$table_id = $_POST['tableNumValue'];
$name = $_POST['nameValue'];
$lastname = $_POST['lastNameValue'];
$phone = $_POST['phoneValue'];
$email = $_POST['emailValue'];
$time_start = $_POST['startTimeValue'];
$time_end = $_POST['EndTimeValue'];
$table_id = $_POST['tableNumValue'];
$count_people = $_POST['countPeople'];


do {
	$rand = rand(100000,999999);
	$check_rand = mysql_query("select no_ref FROM reservation WHERE no_ref='$rand';");
}while(mysql_num_rows($check_rand) > 0);

$insert_reservation = mysql_query("INSERT INTO reservation VALUES('$name','$lastname','$phone','$email','$time_start','$time_end','$table_id','$count_people','$rand','0')");
$insert_table = mysql_query("INSERT INTO table$table_id VALUES('','$time_start','$time_end','0','$rand')");

if(mysql_affected_rows($con)==0) {
	echo "<br><center><div id='true_confirm''><img src='pic/f.png'><font size='5px' color='red'> ไม่สามารถลงทะเบียนได้</font></div>";
	echo "<br><br>";
	echo "<font color='#FF8c00' size='4px'>โปรดลงทะเบียนอีกครั้งในภายหลัง</font></center>";
	echo "<br><br><br>";
	echo "<a href='./'><font color='#666666'>&nbsp;&nbsp;กลับสู่หน้าหลัก</font></a><br><br>";
} else {
	echo "<br><center><div id='true_confirm''><img src='pic/true_icon.png'><font size='6px' color='#FF8C00'>ลงทะเบียนเรีบยร้อยแล้ว</font></div>";
	echo "<br><br>";
	echo "<font size='5px' color='#FF8c00'>รหัสอ้างอิงของคุณคือ : </font>"."<font size='5px' color='red'><b>$rand</b></font></center>";
	echo "<br><br><br>";
	echo "<a href='../'><font color='#666666'>&nbsp;&nbsp;กลับสู่หน้าหลัก</font></a><br><br>";

}

mysql_close($con);

?>